package edu.ccut.saturn.workflow.start;

import java.util.HashMap;
import java.util.Map.Entry;

import edu.ccut.saturn.component.DefaultComponent;
import edu.ccut.saturn.component.IParameterContext;

public class GetByteArrContent extends DefaultComponent {
	@SuppressWarnings("unchecked")
	@Override
	public void execute(IParameterContext parameterContext) throws Exception {
		HashMap<String,String> paramMap = (HashMap<String,String>)parameterContext.getParameterValue(0);
		if(paramMap!=null){
			StringBuffer xml = new StringBuffer();
			xml.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><root><data>");
			for(Entry<String,String> param :paramMap.entrySet()){
				xml.append("<").append((String)param.getKey()).append(">");
				xml.append((String)param.getValue());
				xml.append("</").append((String)param.getKey()).append(">");
			}
			xml.append("</data></root>");
			//TODO 给过来的map中的中文就是乱马, 按utf-8
			parameterContext.setParameter(1, xml.toString().getBytes("UTF-8"));			
		}else{
			parameterContext.setParameter(1, null);		
		}

	}
}